;;; init-frame.el -*- lexical-binding: t; -*-

;;----------------------------------------------------------------------
;; Logo & title
;;----------------------------------------------------------------------

;; Logo
(setq fancy-splash-image canary\logo)

;; Title
(setq frame-title-format
      '("Canary Emacs - "
        (:eval (if (buffer-file-name)
                   (abbreviate-file-name (buffer-file-name))
                 "%b"))))
(setq icon-title-format frame-title-format)



;;----------------------------------------------------------------------
;; Stop C-z from minimizing windows under macOS and Linux
;;----------------------------------------------------------------------
(defun canary-maybe-suspend-frame ()
  (interactive)
  (unless (or *sys-is-mac-x* *sys-is-linux-x*)
    (suspend-frame)))

(global-set-key (kbd "C-z") 'canary-maybe-suspend-frame)



;;----------------------------------------------------------------------
;; Suppress GUI features
;;----------------------------------------------------------------------

(setq use-file-dialog nil)
(setq use-dialog-box nil)
(setq inhibit-startup-screen t)         ; don't show the welcome screen
(setq inhibit-startup-message t)
(setq inhibit-startup-echo-area-message t)



;;----------------------------------------------------------------------
;; Window features
;;----------------------------------------------------------------------

;; Menu/Tool/Scroll bars
(unless *sys-is-mac-x*
  (menu-bar-mode -1))
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
(when (fboundp 'set-scroll-bar-mode)
  (set-scroll-bar-mode nil))

;; Border
(let ((no-border '(internal-border-width . 0)))
  (add-to-list 'default-frame-alist no-border)
  (add-to-list 'initial-frame-alist no-border))

;; Line and Column
(setq-default fill-column 80)
(setq column-number-mode t)
(setq line-number-mode t)

;; Mouse & Smooth Scroll
;; Scroll one line at a time (less "jumpy" than defaults)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)
(setq scroll-step 1
      scroll-margin 0
      scroll-conservatively 100000)

;; Misc
(blink-cursor-mode -1)                    ; don't twinkle the cursor
(transient-mark-mode 1)                   ; highlight selection
(setq visible-bell t)
(setq line-move-visual nil)               ; moves between existing lines
(setq track-eol t)                        ; keep cursor at end of lines, `line-move-visual' must be nil
(setq idle-update-delay 2)                ; update UI less often
(when (boundp 'ns-pop-up-frames)          ; don't open a file in a frame
  (setq ns-pop-up-frames nil))
(when (boundp 'x-gtk-use-system-tooltips) ; don't use GTK+ tooltip
  (setq x-gtk-use-system-tooltips nil))



;;----------------------------------------------------------------------
;; Startup screen
;;----------------------------------------------------------------------

;; Maximize
;; taken from Spacemacs: https://github.com/syl20bnr/spacemacs
(when canary\frame-maximized-at-startup
  (unless (frame-parameter nil 'fullscreen)
    (toggle-frame-maximized))
  (add-to-list 'default-frame-alist '(fullscreen . maximized)))

;; Fullscreen
(when canary\frame-fullscreen-at-startup
  (if canary\frame-fullscreen-use-native
      (toggle-frame-fullscreen)
    (toggle-frame-fullscreen-non-native)))

;; taken from Spacemacs: https://github.com/syl20bnr/spacemacs
(defun toggle-frame-fullscreen-non-native ()
  "Toggle full screen non-natively. Uses the `fullboth' frame paramerter
   rather than `fullscreen'. Useful to fullscreen on macOS w/o animations."
  (interactive)
  (modify-frame-parameters
   nil
   `((maximized
      . ,(unless (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
	         (frame-parameter nil 'fullscreen)))
     (fullscreen
      . ,(if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
	           (if (eq (frame-parameter nil 'maximized) 'maximized)
		             'maximized)
	         'fullboth)))))

(provide 'init-frame)
